<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${requestScope.painter.name}画家作品排序</title>
<link href="../style/css_member.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<style type="text/css">
.table_tr{cursor: pointer;background: #ffffff;}
.table_tr td{padding: 5px 10px;text-align: center;}
</style>
<script type="text/javascript">

$(function(){
	
		$(".table_tr").hover(function(){
			$(this).css({background:"yellow"});
		},function(){
			$(this).css({background:"#ffffff"});
		}
	);	
});

/******改变作品上传状态 *****/
function changeState(id,status){
	if(status == '2'){
		if (window.confirm("确认删除此作品？")) {
			$.ajax( {
				type : "POST",
				url : "${ctx}/painting/changeUploadState.do?painting.id="+id+"&operateStr="+status,
				timeout : 6000,
				async : false, //ajax同步
				success : function(data, textStatus) {
					if(data == '0000'){
						window.location.reload(true);
					}else{
						alert(data);
					}
				}
			});
		}
	}else{
		$.ajax( {
			type : "POST",
			url : "${ctx}/painting/changeUploadState.do?painting.id="+id+"&operateStr="+status,
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				if(data == '0000'){
					window.location.reload(true);
				}
			}
		});
	}
}

/**更改排序*/
function changeSequence(){
	var sequenceArray = [];
	
	$(".table_tr").each(function(i,n){
	     var id = $(this).children().eq(0).find("input[name='id']").val();
		 sequenceArray[i] = "{"+id + ","+ i+"}";
   });
	
	$.ajax( {
		type : "POST",
		url : "${ctx}/painting/changeSequence.do",
		data: "data="+sequenceArray+"&t="+new Date(),
		timeout : 6000,
		async : false, //ajax同步
		success : function(data) {
			if(data == '0000'){
				alert("排序成功");
				location.href = "${ctx}/painting/paintingAction!listAllPaintingsOfPainter.do?painter_Id=${requestScope.painter.id}";
				return;
			}else{
				alert("排序失败");
			}
		}
	});
}

/**放弃排序**/
function cancelSequence(){
	location.href = "${ctx}/painting/paintingAction!listAllPaintingsOfPainter.do?painter_Id=${requestScope.painter.id}";
}
</script>
</head>

<body>

<!-- 页面头部  -->
<jsp:include page="/commons/head_member.jsp"></jsp:include>


<div style="margin: 0 auto;width:960px;background: #ffffff;border: 1px solid #ccc;">
		<div style="margin: 0 auto;width:960px;">
			<div style="width: 170px;float: left;font-size: 14px;font-weight: bold;padding: 10px 0px 10px 15px;float: left;"><a href="${ctx}/painter/showDetail.do?painter.id=${requestScope.painter.id}">${requestScope.painter.name}</a>作品</div>
			<div style="color: red;font-size: 16px;font-weight: bold;width: 600;text-align: center;padding: 10px 0px;float: left;">
				温馨提示:若要调整顺序,请先将该条目置顶,再上下移动调整。最后点击"确认排序"按钮即可
			</div>
		</div>
		<div style="margin: 0 auto;width:960px;">
           <table width="930" border="0" cellpadding="0" cellspacing="1" bordercolor="#0099CC" bgcolor="#0099CC"  id="data_table" align="center">
                <tr bgcolor="#CDE1ED">
                  <td class="nw12b" align="center" height="30">序号</td>
                  <td class="nw12b">主题</td>
                  <td class="nw12b">发布者</td>
                  <td class="nw12b">发布时间</td>
                  <td class="nw12b">审核状态</td>
                  <td class="nw12b">编辑</td>
                </tr>
                 <c:forEach items="${requestScope.paintingList}" var="result" varStatus="status">
	                 <tr class="table_tr">
		                  <td height="30">
			                 	${status.count }
			                 	<input type="hidden" name="id" id="id_${status.index }" value="${result.id }"/>
			                 	<input type="hidden" name="sortflag" id="sortflag_${status.index }" value="${result.sortFlag }"/>
		                   </td>
		                   <td>
		                  	 	<a href="${ctx}/front/backgroundAction!showDetail.do?id=${result.id }" target="_blank">
		                   			${result.title }
		                   		</a>
		                   </td>
		                   <td>${result.entryPerson.username }</td>
		                   <td><fmt:formatDate value="${result.uploadTime }" pattern="yyyy-MM-dd HH:mm"/></td>
		                   <td>${result.auditState.name }</td>
		                   <td>
			             	 <c:choose>
								<c:when test="${result.sortFlag == 0 }">
									<a style="color: blue;"  href="javascript:changeState(${result.id },'6')">置顶</a>
								</c:when>
								<c:otherwise>
									<a style="color: blue;"  href="javascript:changeState(${result.id },'7')">取消置顶</a>
								</c:otherwise>
							</c:choose>
								<input type="button" value="↑" onclick="moveUp()" style="cursor:pointer;"/>
								<input type="button" value="↓" onclick="moveDown()" style="cursor:pointer;"/>
		                   </td>
	                  </tr>
               	 </c:forEach>
            </table>
           </div>
	       <div class="nw12a">
	              		<input type="button" name="btn_changeSequence" id="btn_changeSequence" onclick="changeSequence()" style="cursor: pointer;" value="确认排序"/>
	              		<input type="button" name="cancel_changeSequence" id="cancel_changeSequence" onclick="cancelSequence()" style="cursor: pointer;" value="放弃排序"/>
	       </div>
</div>
    
<jsp:include page="/commons/foot_member.jsp"></jsp:include>

</body>
</html>